"""
Copyright (c) 2022 Huawei Technologies Co.,Ltd.

openGauss is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:

          http://license.coscl.org.cn/MulanPSL2

THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
"""
"""
Case Type   : 统一数据库管理工具
Case Name   : cm_ctl check，检测实例进程运行状态 基本参数验证
Create At   : 2022-07-07
Owner       : @daiguatutu
Description :
    1.cm_ctl check，检测实例进程运行状态
Expect      :
    2.检查成功，无返回值，且无报错
History     : 
"""

import os
import unittest
from yat.test import Node
from yat.test import macro
from testcase.utils.CommonSH import CommonSH
from testcase.utils.Logger import Logger

Pri_U_SH = CommonSH('PrimaryDbUser')
Node_Num = Pri_U_SH.get_node_num()


@unittest.skipIf(3 > Node_Num, '不满足一主两备环境跳过')
class Tools(unittest.TestCase):
    def setUp(self):
        self.log = Logger()
        self.dbuser_node = Node('dbuser')
        self.log.info(f"-----{os.path.basename(__file__)} start-----")

    def test_server_tools1(self):
        text = '--step1:cm_ctl check，检测实例进程运行状态 expect:查询成功，无返回值，无报错--'
        self.log.info(text)
        cmctl_cmd = f'''source {macro.DB_ENV_PATH}
                    cm_ctl check -B cm_agent -T {macro.DB_INSTANCE_PATH};
                    cm_ctl check -B cm_server -T {macro.DB_INSTANCE_PATH};
                    cm_ctl check -B gaussdb -T {macro.DB_INSTANCE_PATH};'''
        self.log.info(cmctl_cmd)
        cmctl_cmd = self.dbuser_node.sh(cmctl_cmd).result()
        self.log.info(cmctl_cmd)
        self.assertEqual('', cmctl_cmd)

    def tearDown(self):
        self.log.info('--无需清理环境--')
        self.log.info(f"-----{os.path.basename(__file__)} end-----")
